using System;

using Microsoft.SPOT;

using mfRCF.Core;

using OST.Persistence;
using OST.Shared;
using mfLogger;

namespace OST.Commands
{
    /// <summary>
    /// initializes/appends the ost rest-commands in <see cref="mfRcf"/>
    /// </summary>
    public static class CommandInitializer
    {
        /// <summary>
        /// wrapper-property 4 logging
        /// </summary>
        private static ILoggerAppender Logger
        {
            get
            {
                return mfLogger.mfLogger.Instance;
            }
        }

        public static void AppendCommands()
        {
            mfRcf.Instance.Commands.Add(new WebClientGETCommand("/"));//return index.htm
            mfRcf.Instance.Commands.Add(new WebClientPOSTCommand("/"));//update index.htm
            mfRcf.Instance.Commands.Add(new OSTImageGETCommand("/ost.png"));//return ost.png
            mfRcf.Instance.Commands.Add(new OSTImageGETCommand("/favicon.ico"));//return ost.png on 'favicon.ico'-request

            mfRcf.Instance.Commands.Add(new ConfigurationGETCommand("/configuration"));
            mfRcf.Instance.Commands.Add(new ConfigurationApplyGETCommand("/configuration/apply"));
            //throws OutOfMemoryException on netuinoplus2, caus of XmlReader-Resources
            //mfRcf.Instance.Commands.Add(new ConfigurationPOSTCommand("/configuration"));

            if (ConfigurationProvider.Instance.HasConfig)
            {
                var config = ConfigurationProvider.Instance.ConfigInstance;

                mfRcf.Instance.Commands.Add(new SetConfigurationGETCommand("/configuration/logging", config.Logging));//?PropertyName=newValue
                mfRcf.Instance.Commands.Add(new SetConfigurationGETCommand("/configuration/location", config.Location));//?PropertyName=newValue
                mfRcf.Instance.Commands.Add(new SetConfigurationGETCommand("/configuration/timeservice", config.TimeService));//?PropertyName=newValue
                mfRcf.Instance.Commands.Add(new SetConfigurationGETCommand("/configuration/frame", config.Frame));//?PropertyName=newValue
                mfRcf.Instance.Commands.Add(new SetConfigurationGETCommand("/configuration/motor", config.Motor));//?PropertyName=newValue
                mfRcf.Instance.Commands.Add(new SetConfigurationGETCommand("/configuration/ethernet", config.Ethernet));//?PropertyName=newValue
            }
            else
            {
                Logger.Warning("no config for modify-config-commands available!");
            }

            mfRcf.Instance.Commands.Add(new CalculateFrameCenterGETCommand("/calculation/center"));

            mfRcf.Instance.Commands.Add(new MotorPositionGETCommand("/motor"));
            mfRcf.Instance.Commands.Add(new MotorInitGETCommand("/motor/init"));
            mfRcf.Instance.Commands.Add(new MotorCalibrateGETCommand("/motor/calibrate"));
            mfRcf.Instance.Commands.Add(new MotorDriveManualGETCommand("/motor/drive2"));//?position={0}
            mfRcf.Instance.Commands.Add(new MotorDrive2CenterGETCommand("/motor/drive2center"));
            mfRcf.Instance.Commands.Add(new MotorMoveUpGETCommand("/motor/moveup"));
            mfRcf.Instance.Commands.Add(new MotorMoveDownGETCommand("/motor/movedown"));
            mfRcf.Instance.Commands.Add(new MotorDrivingDirectionGETCommand("/motor/drivingdirection"));
            mfRcf.Instance.Commands.Add(new MotorStopGETCommand("/motor/stop"));

            mfRcf.Instance.Commands.Add(new TrackerActionsGETCommand("/tracker/"));
            mfRcf.Instance.Commands.Add(new TrackerStartGETCommand("/tracker/start"));
            mfRcf.Instance.Commands.Add(new TrackerStopGETCommand("/tracker/stop"));
            mfRcf.Instance.Commands.Add(new TrackerNextActionGETCommand("/tracker/next"));
            mfRcf.Instance.Commands.Add(new TrackerWindAlarmGETCommand("/tracker/windalarm"));

            mfRcf.Instance.Commands.Add(new DateGETCommand("/date"));
            mfRcf.Instance.Commands.Add(new DatePOSTCommand("/date"));

            mfRcf.Instance.Commands.Add(new UpdateNTPGETCommand("/ntp/update"));

            mfRcf.Instance.Commands.Add(new WindSpeedGETCommand("/wind"));
            mfRcf.Instance.Commands.Add(new WindSpeedAverageGETCommand("/wind/average"));

            mfRcf.Instance.Commands.Add(new GCFreeBytesGETCommand("/system/gc"));
            mfRcf.Instance.Commands.Add(new RebootGETCommand("/system/reboot"));
            mfRcf.Instance.Commands.Add(new UptimeGETCommand("/system/uptime"));
            mfRcf.Instance.Commands.Add(new VersionGETCommand("/system/Version"));

#if DEBUG
            mfRcf.Instance.Commands.Add(new TestGETCommand("/test")); 
#endif

            Logger.Debug("commands appended");
        }
    }
}
